<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 
/* ======================================================================*\
  || #################################################################### ||
  || # ND.Tiep CODER Tutorial                                           # ||
  || # ---------------------------------------------------------------- # ||
  || # Copyright ©2013 Nguyen Dinh Tiep. All Rights Reserved.           # ||
  || # Please do not remove this comment lines.                         # ||
  || # -------------------- LAST MODIFY INFORMATION ------------------- # ||
  || # Author by: Nguyen Dinh Tiep                                      # ||
  || #################################################################### ||
  \*====================================================================== */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*\
  |*-------Please specify source when using my code or a part of them-----*|
  \*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
class Captcha {

    function __construct() {
        
    }

    private function randomtext($min, $max) {
        $string = md5(rand($min, $max));
        return $string;
    }

    public function captcha_text($dodai) {
        $chuoi = $this->randomtext(0, 99999);
        $chuoi = substr($chuoi, "0", $dodai);
        Session::_set("captcha_keys", $chuoi);
        return $chuoi;
    }

    private function create_images($captra_text) {
        ob_clean();
       Session::_set("captcha_keys", $captra_text);
        $width = 100;
        $height = 30;
        $rgb1 = rand(1, 255);
        $rgb2 = rand(1, 255);
        $rgb3 = rand(1, 255);
        $image = ImageCreate($width, $height);
        $white = ImageColorAllocate($image, $rgb1, $rgb2, $rgb3);
        $black = ImageColorAllocate($image, 0, 0, 0);
        ImageFill($image, 0, 0, $black);
        ImageString($image, 5, 30, 6, $captra_text, $white);
       header("Content-type: image/jpeg");
        ImageJpeg($image);
        ImageDestroy($image);
       
       
    }

    public function captcha_question($arcaptra) {
        $question = array_rand($arcaptra);
        $replices = $arcaptra[$question];
        $captcha[$question] = $replices;
        Session::_set("captcha_keys", $replices);
        return $captcha;
         
    }

    public function create_captcha_images($dodai) {
        $chuoi = $this->randomtext(0, 99999);
        $chuoi = substr($chuoi, "0", $dodai);
       $captra = $this->create_images($chuoi);
      
    }
    public function captcha_images(){
        $string = "<img src='".__URL__."/maxacnhan'></img>";
        return $string;
    }

}